package com.itheima.health.testdate;


import com.itheima.health.utils.DateUtils;
import org.junit.Test;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;


public class testDate {
@Test
 public void test01()throws Exception{
    Date lastDay4ThisMonth = DateUtils.getLastDay4ThisMonth();
    System.out.println(lastDay4ThisMonth);
}

    @Test
    public void test02()throws Exception{



        String dates = "Thu Sep 07 2017 00:00:00 GMT+0800 (中国标准时间) 00:00:00";
        SimpleDateFormat sdf = new SimpleDateFormat("EEE MMM dd yyyy HH:mm:ss 'GMT'Z", Locale.ENGLISH);

        Date date = sdf.parse(dates );

        String res = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").format(date);

        System.out.println(res);

    }

    @Test
    public void test03()throws Exception{

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

        Date date = new Date();

        String str = sdf.format(date);

        System.out.println(str);
    }

    @Test
    public void test04()throws Exception{

        Calendar calendar = Calendar.getInstance();

        System.out.println(calendar.getActualMaximum(Calendar.DATE));

        calendar.add(Calendar.MONTH,-1 );

        calendar.set(Calendar.DATE,calendar.getActualMaximum(Calendar.DATE) );

        Date lastDay = calendar.getTime();

        DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");

        System.out.println(dateFormat.format(lastDay));
    }

    @Test
    public void test05()throws Exception{

        Calendar calendar = Calendar.getInstance();

        calendar.set(Calendar.DAY_OF_MONTH, 1);
        calendar.add(Calendar.DATE, -1);

        Date date = calendar.getTime();

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

        System.out.println(sdf.format(date));

        /*String dd = sdf.format(date  );

        System.out.println(dd);*/
    }
}
